home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Scene Storm
/
Scene Storm - Volume 1.iso
/
coding
/
c
/
northc
/
example1.lzh
/
cRender
/
aif.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-30
|
10KB
|
360 lines
/*
(c) 1990 S.Hawtin.
Permission is granted to copy this file provided
1) It is not used for commercial gain
2) This notice is included in all copies
3) Altered copies are marked as such
No liability is accepted for the contents of the file.
aif.c within NorthC render
*/
/*
The Amiga interface functions
*/
#include <stdio.h>
#include <types.h>
#include <intuition/intuition.h>
#include <graphics/rastport.h>
#include <graphics/gfx.h>
#include <graphics/view.h>
#include <intuition/screens.h>
#include "3d.h"
extern struct Screen *OpenScreen();
extern struct Window *OpenWindow();
extern struct ViewPort *ViewPortAddress();
extern long OpenLibrary();
extern struct Message *GetMsg();
extern struct ColorMap *GetColorMap();
extern PLANEPTR AllocRaster();
extern long Request();
void shut_screen();
extern int solid_fill;
extern double rot1;
extern double rot2;
UWORD area1Buffer[25];
UWORD area2Buffer[25];
/* Get the menustrip data structures */
#include "menustrip.h"
/* Get the requester data structure */
#include "requester.h"
PLANEPTR myplane1;
PLANEPTR myplane2;
int midx,midy;
struct TmpRas myTmpRas1;
struct TmpRas myTmpRas2;
struct NewWindow init_win;
struct Window *mywin;
struct Window *win1,*win2;
struct NewScreen init_scn;
struct Screen *myscreen;
struct AreaInfo myArea1;
struct AreaInfo myArea2;
struct ViewPort *myvport;
short colours[16] =
{0x0000,0x0888,0x0222,0x0333,
0x0444,0x0555,0x0666,0x0777,
0x0888,0x0999,0x0aaa,0x0bbb,
0x0ccc,0x0ddd,0x0eee,0x0fff};
draw_tri(col,x1,y1,x2,y2,x3,y3)
int col;
int x1,y1,x2,y2,x3,y3;
{/* Draw the triangle */
long this_shade;
if(solid_fill)
{/* Set colour for triangle */
if(col>15)
col = 15;
if(col<2)
col = 2;
SetAPen(mywin->RPort,(long)col);
/* Draw the triangle */
AreaMove(mywin->RPort,(long)(x1 + midx),(long)(y1 + midy));
AreaDraw(mywin->RPort,(long)(x2 + midx),(long)(y2 + midy));
AreaDraw(mywin->RPort,(long)(x3 + midx),(long)(y3 + midy));
AreaDraw(mywin->RPort,(long)(x1 + midx),(long)(y1 + midy));
AreaEnd(mywin->RPort);
}
else
{
SetAPen(mywin->RPort,(long)15);
/* Draw the triangle */
Move(mywin->RPort,(long)(x1 + midx),(long)(y1 + midy));
Draw(mywin->RPort,(long)(x2 + midx),(long)(y2 + midy));
Draw(mywin->RPort,(long)(x3 + midx),(long)(y3 + midy));
Draw(mywin->RPort,(long)(x1 + midx),(long)(y1 + midy));
}
}
open_request()
{/* Call the requester to change rotation */
struct IntuiMessage *my_msg;
ULONG class;
USHORT code;
USHORT qualifier;
/* Set up the requester */
sprintf(int1_buffer,"%d",(int)(1000.0*rot1));
sprintf(int2_buffer,"%d",(int)(1000.0*rot2));
class = Request(&my_requester,mywin);
if(class==0)
{printf("Requester failed\n");
exit(EXIT_FAILURE);
}
while(-1)
{/* Wait until we have recieved a message */
my_msg=(struct IntuiMessage *)GetMsg(mywin->UserPort);
while(my_msg!=NULL)
{/* Keep dealing with messages until requester is dismissed */
class = my_msg->Class;
code = my_msg->Code;
qualifier = my_msg->Qualifier;
/* OK now free the message */
ReplyMsg(my_msg);
/* Check which IDCMP flag was sent: */
switch(class)
{
case GADGETDOWN:
/* The user has selected a gadget */
break;
case GADGETUP:
/* The user has released a gadget */
break;
case REQSET:
/* Requester activated */
break;
case REQCLEAR:
/* Requester deactivated */
goto all_done;
}
my_msg=(struct IntuiMessage *)GetMsg(mywin->UserPort);
}
/* Give everthing else a chance */
Delay(20L);
}
all_done:
/* Now read the requester values */
rot1 = ((double)int1_info.LongInt)/1000.0;
rot2 = ((double)int2_info.LongInt)/1000.0;
}
proc_event(class,code,qualifier)
long class;
int code;
int qualifier;
{/* Process the message, should be a menu select */
/* Now go do what the user wants */
if(class == MENUPICK)
{
if( code != MENUNULL )
{
switch(MENUNUM(code))
{case EDIT_MENU:
switch(ITEMNUM(code))
{case QUIT_ITEM:
exit(0);
case SOLID_ITEM:
solid_fill = -1;
break;
case OUTLINE_ITEM:
solid_fill = 0;
break;
case REQ_ITEM:
open_request();
break;
default:
printf("Unknown item\n");
}
break;
default:
printf("Unknown Menu\n");
}
}
}
}
clear_screen()
{
ULONG class;
USHORT code;
USHORT qualifier;
struct IntuiMessage *my_msg;
/* Swap windows */
WindowToFront(mywin);
/* Wait for window to arrive at front */
Delay(15L);
/* process all the waiting events */
my_msg = (struct IntuiMessage *)GetMsg(win2->UserPort);
while(my_msg!=NULL)
{
class = my_msg->Class;
code = my_msg->Code;
qualifier = my_msg->Qualifier;
/* OK now free the message */
ReplyMsg(my_msg);
proc_event(class,(int)code,(int)qualifier);
my_msg = (struct IntuiMessage *)GetMsg(win2->UserPort);
}
my_msg = (struct IntuiMessage *)GetMsg(win1->UserPort);
while(my_msg!=NULL)
{
class = my_msg->Class;
code = my_msg->Code;
qualifier = my_msg->Qualifier;
/* OK now free the message */
ReplyMsg(my_msg);
proc_event(class,(int)code,(int)qualifier);
my_msg = (struct IntuiMessage *)GetMsg(win1->UserPort);
}
/* Swap windows */
if(mywin==win1)
mywin=win2;
else
mywin=win1;
/* Clear off window */
SetAPen(mywin->RPort,0L);
RectFill(mywin->RPort,0L,0L,(long)SC_WIDTH,(long)(SC_HEIGHT-SC_TOP));
}
init_screen()
{/* Open up the window */
int i;
/* Open the intuition library */
if(0==OpenLibrary("intuition.library",0L))
{printf("Unable to open intuition library\n");
exit(EXIT_FAILURE);
}
/* Open the graphics library */
if(0==OpenLibrary("graphics.library",0L))
{printf("Unable to open graphics library\n");
exit(EXIT_FAILURE);
}
/* Ensure we tidy up */
atexit(shut_screen);
/* Open my own screen */
init_scn.LeftEdge = 0;
init_scn.TopEdge = 0;
init_scn.Width = SC_WIDTH;
init_scn.Height = SC_HEIGHT;
init_scn.Depth = 4;
init_scn.Type = CUSTOMSCREEN;
init_scn.DefaultTitle = "NorthC CRender";
init_scn.DetailPen = 15;
init_scn.BlockPen = 8;
myscreen = OpenScreen(&init_scn);
if(myscreen==NULL)
{printf("Failed to open screen\n");
exit(EXIT_FAILURE);
}
/* Set up centre of window */
midx = SC_WIDTH/2;
midy = (SC_HEIGHT - SC_TOP)/2;
/* Open the window */
init_win.LeftEdge = 0;
init_win.TopEdge = SC_TOP;
init_win.Width = SC_WIDTH;
init_win.Height = SC_HEIGHT-SC_TOP;
/* Window cannot resize so just fix it */
init_win.MaxWidth = init_win.Width;
init_win.MaxHeight= init_win.Height;
init_win.MinWidth = init_win.Width;
init_win.MinHeight= init_win.Height;
init_win.DetailPen= 15;
init_win.BlockPen = 8;
init_win.Title = "";
init_win.Screen = myscreen;
init_win.Type = CUSTOMSCREEN;
init_win.Flags = BORDERLESS | SMART_REFRESH | ACTIVATE;
init_win.IDCMPFlags = MENUPICK|GADGETDOWN|GADGETUP|REQCLEAR|REQSET;
/* Now try and open the windows */
win1 = OpenWindow(&init_win);
win2 = OpenWindow(&init_win);
mywin = win1;
if(win1==NULL || win2==NULL)
{printf("Failed to open window\n");
exit(EXIT_FAILURE);
}
/* Set up the menu strip */
SetMenuStrip(win1, &edit_menu );
SetMenuStrip(win2, &edit_menu );
/* Set up the areas */
InitArea(&myArea1,&area1Buffer[0],10L);
win1->RPort->AreaInfo = &myArea1;
InitArea(&myArea2,&area2Buffer[0],10L);
win2->RPort->AreaInfo = &myArea2;
myplane1 = AllocRaster((long)SC_WIDTH,(long)(SC_HEIGHT-SC_TOP));
myplane2 = AllocRaster((long)SC_WIDTH,(long)(SC_HEIGHT-SC_TOP));
if(myplane1==NULL || myplane2==NULL)
{printf("Failed to create plane\n");
exit(EXIT_FAILURE);
}
InitTmpRas(&myTmpRas1,myplane1,(long)RASSIZE(SC_WIDTH,SC_HEIGHT-SC_TOP));
InitTmpRas(&myTmpRas2,myplane1,(long)RASSIZE(SC_WIDTH,SC_HEIGHT-SC_TOP));
/* InitTmpRas(&myTmpRas2,myplane1,(long)RASSIZE(SC_WIDTH,SC_HEIGHT-SC_TOP));
*/ win1->RPort->TmpRas = &myTmpRas1;
win2->RPort->TmpRas = &myTmpRas2;
/* Set the colours to grey */
LoadRGB4(&myscreen->ViewPort,colours,16L);
}
void
shut_screen()
{/* Close down the graphics window, this function is called
when exit() runs or with normal program termination */
if(myplane1)
{
FreeRaster(myplane1,(long)SC_WIDTH,(long)(SC_HEIGHT-SC_TOP));
myplane1 = NULL;
}
if(myplane2)
{
FreeRaster(myplane2,(long)SC_WIDTH,(long)(SC_HEIGHT-SC_TOP));
myplane2 = NULL;
}
if(win1)
{
ClearMenuStrip(win1);
CloseWindow(win1);
win1 = NULL;
}
if(win2)
{
ClearMenuStrip(win2);
CloseWindow(win2);
win2 = NULL;
}
if(myscreen)
CloseScreen(myscreen);
myscreen = NULL;
}